


LIC2CDIR=~/lic2loc
LUS2LICDIR=~/lus2lic
LUS2LIC=$(LUS2LICDIR)/lus2lic
WWW_DIR=/import/www/DIST-TOOLS/SYNCHRONE/lustre-v6

ifeq ($(HOSTTYPE),cygwin)
WWW_DIR=//ARPONT/www-verimag/DIST-TOOLS/SYNCHRONE/lustre-v6
endif

VERSION=R0.$(shell $(LUS2LIC) -version  | cut -d " " -f 1 | cut -d "." -f 2)

RELNAME_PREFIX=lv6-alpha-$(VERSION)

RELNAME=$(RELNAME_PREFIX)-$(shell date +%d-%m-%y)-$(HOSTTYPE)


release: $(RELNAME) doc lus2lic test_files $(RELNAME).tgz
rel:release

xxx:
	echo "RELNAME_PREFIX='$(RELNAME_PREFIX)'"
	echo "RELNAME='$(RELNAME)'"


.PHONY: $(RELNAME)
$(RELNAME):
	rm -rf $(RELNAME)  || true
	mkdir $(RELNAME) || true
	cp -rf rel-skel/* $(RELNAME)/

doc:
	cp $(LUS2LICDIR)/lv6-ref-man/lv6-ref-man.pdf $(RELNAME)/doc
	cp ~/slides/lv6/*.pdf  $(RELNAME)/doc
	cp $(LUS2LICDIR)/utils/lustre.el  $(RELNAME)/utils

.PHONY:lus2lic
lus2lic:
	cd $(LUS2LICDIR)/ ; make 
	cp $(LUS2LIC) $(RELNAME)/bin/

lus2licbc:
	cd $(LUS2LICDIR)/src ; make bc
	cp $(LUS2LIC) $(RELNAME)/bin/

lic2c:
	cd $(LIC2CDIR)/src/ ; make clean ; make 
	cp $(LIC2CDIR)/src/lic2c $(RELNAME)/bin/

test_files:
	mkdir $(RELNAME)/test/ || true
	cp -rf $(LUS2LICDIR)/test/should_work $(RELNAME)/test/
	cp -rf $(LUS2LICDIR)/test/should_fail $(RELNAME)/test/
	cp -rf $(LUS2LICDIR)/test/lus2lic.tests $(RELNAME)/test/
	cp -rf $(LUS2LICDIR)/test/Makefile.dist $(RELNAME)/test/Makefile
	cp -rf $(LUS2LICDIR)/test/site.exp $(RELNAME)/test/
	cp -rf $(LUS2LICDIR)/test/config $(RELNAME)/test/
	cp -rf $(LUS2LICDIR)/test/myec2c $(RELNAME)/test/
	cp -rf $(shell which lurettetop) $(RELNAME)/test/
	cp -rf $(LUS2LICDIR)/utils/lustrequiv $(RELNAME)/utils
	cp -rf $(LUS2LICDIR)/utils/luciole-rif $(RELNAME)/utils
	cp -rf $(LUS2LICDIR)/utils/test_lus2lic_no_node $(RELNAME)/utils
	cp -rf $(LUS2LICDIR)/utils/compare_exec_and_2c $(RELNAME)/utils
	cp -rf `which lurettetop` $(RELNAME)/test
	cp -rf `which lurettetop`_exe $(RELNAME)/test
	rm -f $(RELNAME)/test/*/*~
	rm -f $(RELNAME)/test/*/*/*~
	rm -f $(RELNAME)/test/*/normal.lus
	rm -f $(RELNAME)/test/*/*/normal.lus
	rm -f $(RELNAME)/test/*/ELMU.lus
	rm -f $(RELNAME)/test/*/*/ELMU.lus
	rm -f $(RELNAME)/test/*/onlyroll*.lus
	rm -f $(RELNAME)/test/*/*/onlyroll*.lus
	rm -f $(RELNAME)/test/*/pilote-1.0.lus
	rm -f $(RELNAME)/test/*/*/pilote-1.0.lus
	rm -f $(RELNAME)/test/*/car*.lus
	rm -f $(RELNAME)/test/*/*/car*.lus
	rm -f $(RELNAME)/test/*/Gyro*.lus
	rm -f $(RELNAME)/test/*/*/Gyro*.lus
	for f in $(shell find $(LUS2LICDIR)/test/should_work -name \*.lus); do \
		 ($(RELNAME)/bin/lus2lic $$f -o /tmp/xx.lus || (echo "*** lus2lic $$f failed" ; exit 1)) && \
		echo "cp $$f $(RELNAME)/test/" && \
		cp $$f $(RELNAME)/test/; \
	done

EXAMPLES=ex
test_files2:
	cp -rf $(LUS2LICDIR)/test/should_work/*.lus $(EXAMPLES)/
	rm -f $(EXAMPLES)/normal.lus
	rm -f $(EXAMPLES)/ELMU.lus
	rm -f $(EXAMPLES)/onlyroll*.lus
	rm -f $(EXAMPLES)/pilote-1.0.lus
	rm -f $(EXAMPLES)/car*.lus
	rm -f $(EXAMPLES)/Gyro*.lus
	rm -f $(EXAMPLES)/Gyro*.lus

test_files2_clean:
	for f in $(shell find $(LUS2LICDIR)/test/should_work -name \*.lus); do \
		 (lus2lic $$f -o /tmp/xx.lus || (echo "*** lus2lic $$f failed" ; exit 1)) && \
		echo "cp $$f $(EXAMPLES)/valid" && \
		cp $$f $(EXAMPLES)/valid; \
	done

#		 ($(RELNAME)/bin/lic2c --out-format loc  /tmp/xx.lus > /dev/null || (echo "*** lic2c $$f failed" ; exit 1)) && 


.PHONY:$(RELNAME).tgz
$(RELNAME).tgz:
	tar cvfz $(RELNAME).tgz $(RELNAME) 

www:  $(RELNAME).tgz
	cp $(RELNAME).tgz $(WWW_DIR)
	cp $(LUS2LICDIR)/lv6-ref-man/lv6-ref-man.pdf  $(WWW_DIR)/doc/


LAB_INSTALL_DIR=/usr/local/tools/lustre/v6
LAB_INSTALL_DIR=/import/linux/x86_64/tools/lustre/v6
verimag: 
	cp $(RELNAME).tgz $(LAB_INSTALL_DIR)
	cd $(LAB_INSTALL_DIR)  ; tar xvfz $(RELNAME).tgz
	rm -f $(LAB_INSTALL_DIR)/current
	ln -s $(LAB_INSTALL_DIR)/$(RELNAME)  $(LAB_INSTALL_DIR)/current


clean:
	rm -rf $(RELNAME_PREFIX)*-*

test-rel:
	cp  $(RELNAME).tgz /tmp && \
	cd /tmp && \
	rm -rf $(RELNAME) && \
	tar xvfz $(RELNAME).tgz && \
	cd /tmp/$(RELNAME)/test ; make test

all: rel
